define(
   [
      'dojo/_base/declare',
      'dojo/_base/lang',
      'dojo/Evented',
      'dijit/_WidgetBase',
      'dijit/_TemplatedMixin',
      'dijit/form/Button',
      'dojox/form/BusyButton',
      'dojo/text!./templates/buttonRow.html'
   ],
   function(declare, lang, evented, _WidgetBase, _TemplatedMixin, Button, BusyButton, template)
   {
      return declare("noBusinessBase/widgets/ButtonRow", [_WidgetBase, _TemplatedMixin, evented],
      {
         //Path to the template
         templateString: template,
      
         widgetsInTemplate: true,
         baseClass: 'NoBusinessButtonRow',
      
         mBack: true,
         mBackLabel: "Back",
         mBackIconClass: "icons-fugue-icons-16x16-arrow-180",
         mCancel: true,
         mCancelabel: "Cancel",
         mCancelIconClass: "icons-fugue-icons-16x16-cross-script",
         mNext: true,
         mNextLabel: "Next",
         mNextIconClass: "icons-fugue-icons-16x16-arrow",
         mSubmit: true,
         mSubmitBusyLabel: "Submitting...",
         mSubmitIconClass: "icons-fugue-icons-16x16-disk-black",
         mSubmitLabel: "Submit",
         postscript: function(args)
         {
            this.inherited(arguments);
         },
         postCreate: function()
         {
            // Run any parent postCreate processes - can be done at any point
            this.inherited(arguments);
            
            if(this.mBack)
            {
               this.mBackButton = new Button({
                  label: this.mBackLabel,
                  iconClass: 'dijitIcon ' + this.mBackIconClass,
                  onClick: lang.hitch(this, function(){
                     this.emit('back');
                  })
               }, this.mAttachPointForNoBusinessBackButton);
            }
            
            if(this.mNext)
            {
               this.mNextButton = new Button({
                  label: this.mNextLabel,
                  iconClass: 'dijitIcon ' + this.mNextIconClass,
                  onClick: lang.hitch(this, function(){
                     this.emit('next');
                  })
               }, this.mAttachPointForNoBusinessNextButton);
            }
            
            if(this.mSubmit)
            {
               this.mSubmitButton = new BusyButton({
                  label: this.mSubmitLabel,
                  type: 'submit',
                  busyLabel: this.mSubmitBusyLabel,
                  iconClass: 'dijitIcon ' + this.mSubmitIconClass,
                  onClick: lang.hitch(this, function() {
                     if(this.mCancelButton)
                        this.mCancelButton.set('disabled', true);
                     if(this.mNext)
                        this.mNextButton.set('disabled', true);
                     if(this.mBack)
                        this.mBackButton.set('disabled', true);
                     this.emit('submit');
                  })
               }, this.mAttachPointForNoBusinessSubmitButton);
            }
            
            if(this.mCancel)
            {
               this.mCancelButton = new Button({
                  label: this.mCancelabel,
                  iconClass: 'dijitIcon ' + this.mCancelIconClass,
                  onClick: lang.hitch(this, function() {
                     this.mCancelButton.set('disabled', true);
                     if(this.mSubmitButton)
                        this.mSubmitButton.set('disabled', true);
                     if(this.mNext)
                        this.mNextButton.set('disabled', true);
                     if(this.mBack)
                        this.mBackButton.set('disabled', true);
                     this.emit('cancel');
                  })
               }, this.mAttachPointForNoBusinessCancelButton);
            }
         },
         reset: function()
         {
            setTimeout(lang.hitch(this, function(){
               if(this.mSubmitButton)
               {
                  this.mSubmitButton.cancel();
                  this.mSubmitButton.set('disabled', false);
               }
               
               if(this.mCancelButton)
                  this.mCancelButton.set('disabled', false);
               
               if(this.mNext)
                  this.mNextButton.set('disabled', false);

               if(this.mBack)
                  this.mBackButton.set('disabled', false);
            }), 10);
         },
         submitHidden: function(hidden)
         {
            dojo.style(this.mSubmitButton.domNode, {
               visibility: (hidden ? 'hidden' : 'visible'),
               display:    (hidden ? 'none' : 'block')
            });
         }
      });
   }
);
